/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package quanlinganhang.view;

import java.awt.Image;

/**
 * Một custom message dialog để hiển thị thông báo ra cho người dùng
 *
 * @author phamduong
 */
public class CustomMessageDialog extends javax.swing.JDialog {

    public static final int OK = 1;
    public static final int CANCEL = 0;
    public static final int MESSAGE = 2;
    public static final int CONFIRM = 3;
    public static final int DONE = 4;
    public static int STATUS = 0;

    /**
     * Creates new form CustomMessageDialog
     */
    public CustomMessageDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        //Image icon = getToolkit().getImage(getClass().getResource("/quanlinganhang.resources/volume.png"));
//        setIconImage(icon);
    }

    /**
     * Hàm khởi tạo
     *
     * @param parent
     * @param modal
     * @param title Title của MessageBox
     * @param confirm_message Nội dung của MesageBox
     * @param type Loại MessageBox (thông báo hay xác nhận hay thông báo hoàn
     * thành)
     */
    public CustomMessageDialog(java.awt.Frame parent, boolean modal, String title, String confirm_message, int type) {
        super(parent, modal);
        initComponents();
        //Image icon = getToolkit().getImage(getClass().getResource("/quanlinganhang.resources/volume.png"));
//        this.setIconImage(icon);
        lbContent.setText(confirm_message);
        setTitle(title);
        STATUS = 0;

        //nếu đơn thuần là thông báo thông tin cho người dùng
        if (type == MESSAGE) {
            btCancel.setVisible(false);
            btOk.setVisible(false);
            btMessage.setVisible(true);
            btMessage.setLocation(120, 80);
        }
        //thông báo đòi người dùng xác nhận
        else if (type == CONFIRM) {
            btCancel.setVisible(true);
            btCancel.setLocation(120, 80);
            btOk.setVisible(true);
            btOk.setLocation(60, 80);
            btMessage.setVisible(false);
            //lbImage.setIcon(new javax.swing.ImageIcon(getClass().getResource("/quanlinganhang.resources/question.png")));
        }
        //thông báo hoàn thành task
        else if (type == DONE) {
            btCancel.setVisible(false);
            btOk.setVisible(false);
            btMessage.setVisible(true);
            btMessage.setLocation(120, 80);
            //lbImage.setIcon(new javax.swing.ImageIcon(getClass().getResource("/quanlinganhang.resources/done.png")));
        }
        setLocationRelativeTo(this);
        setVisible(true);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lbImage = new javax.swing.JLabel();
        lbContent = new javax.swing.JLabel();
        btOk = new javax.swing.JButton();
        btMessage = new javax.swing.JButton();
        btCancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        lbImage.setIcon(new javax.swing.ImageIcon(getClass().getResource("/quanlinganhang/resources/about_32.png"))); // NOI18N

        lbContent.setText("Hiển thị nội dung thông báo!");

        btOk.setIcon(new javax.swing.ImageIcon(getClass().getResource("/quanlinganhang/resources/ok.png"))); // NOI18N
        btOk.setText("OK");
        btOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btOkActionPerformed(evt);
            }
        });

        btMessage.setIcon(new javax.swing.ImageIcon(getClass().getResource("/quanlinganhang/resources/ok.png"))); // NOI18N
        btMessage.setText("OK");
        btMessage.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btMessageActionPerformed(evt);
            }
        });

        btCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/quanlinganhang/resources/no.png"))); // NOI18N
        btCancel.setText("Hủy");
        btCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(lbImage)
                        .addGap(18, 18, 18)
                        .addComponent(lbContent, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(49, 49, 49)
                        .addComponent(btOk)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btMessage)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btCancel)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addComponent(lbImage)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(lbContent, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(18, 18, 18)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btOk)
                    .addComponent(btMessage)
                    .addComponent(btCancel))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btOkActionPerformed
        // TODO add your handling code here:
        STATUS = OK;
        dispose();
    }//GEN-LAST:event_btOkActionPerformed

    private void btMessageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btMessageActionPerformed
        // TODO add your handling code here:
        //STATUS = MESSAGE;
        dispose();
    }//GEN-LAST:event_btMessageActionPerformed

    private void btCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelActionPerformed
        // TODO add your handling code here:
        STATUS = CANCEL;
        dispose();
    }//GEN-LAST:event_btCancelActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btCancel;
    private javax.swing.JButton btMessage;
    private javax.swing.JButton btOk;
    private javax.swing.JLabel lbContent;
    private javax.swing.JLabel lbImage;
    // End of variables declaration//GEN-END:variables
}
